package com.chis.jmdatatimer.main;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2019年01月27日
 */
public class HbaseConnect {

    public static void main(String[] args) {
        Configuration configuration = HBaseConfiguration.create();
        configuration.set("hbase.rootdir", "hdfs://192.168.150.90:9000/hbase");
        Connection connection = null;
        Admin admin = null;
        try {
            connection = ConnectionFactory.createConnection(configuration);
            admin = connection.getAdmin();
            //查询表
            System.out.println("hbase列表：");
            HTableDescriptor hTableDescriptors[] = admin.listTables();
            for (HTableDescriptor hTableDescriptor : hTableDescriptors) {
                System.out.println(hTableDescriptor.getNameAsString());
            }
            System.out.println("================================");

        } catch (Exception e){
            e.printStackTrace();
        }
        try {
            if (admin != null) {
                admin.close();
            }
            if (null != connection) {
                connection.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
